package com.jerry.hm.algorithm.recursion;

/**
 * 冒泡排序
 *
 * @author Jerry
 * @since 2024/9/30 19:28
 */
public class BubbleSort {

    public static void sort(int[] arr) {
        bubble(arr, arr.length - 1);
    }

    /**
     * 冒泡排序
     *
     * @param arr
     * @param right 有边界索引值
     */
    private static void bubble(int[] arr, int right) {
        if (right == 0) {
            return;
        }
        int divide = 0;
        for (int i = 0; i < right; i++) {
            if (arr[i] > arr[i + 1]) {
                int temp = arr[i];
                arr[i] = arr[i + 1];
                arr[i + 1] = temp;
                divide = i;
            }
        }
        bubble(arr, divide);
    }
}
